﻿
namespace System.Net.DnsToolkit.Util {
    public static class BitStringHelper {

        public static byte[] StringToByteArray(string s) {

            string hex = s.Replace(" ", "");

            int NumberChars = hex.Length;
            byte[] bytes = new byte[NumberChars / 2];
            for (int i = 0; i < NumberChars; i += 2)
                bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
            return bytes;
        }

        public static string ByteArrayToString(byte[] ba) {
            return ByteArrayToString(ba, 0, ba.Length);
        }


        public static string ByteArrayToString(byte[] ba, int offset, int length) {
            string hex = BitConverter.ToString(ba, offset, length);
            return hex.Replace("-", "");
        }


    }
}
